//	--------------------------------------------------------------------
//	Copyright(C) 2006,2007 Zhao Yukun. All rights reserved.
//	This file is a part of the Xeres system.
//	Xeres 2007
//	Contact : xeres.engine@gmail.com
//	$(reservedInfo)
//	$(reservedDeclaration)
//	--------------------------------------------------------------------
///	@file	<frame_composition.fx>
///	@path	~/xeres.engine/res/fx/
///	@date	2008/09/25
///	@desc	UI component sprite shader.

#ifdef _D3D10

// DirectX 10 version.

#include "blending_10.fxh"

struct VS_OUTPUT
{
	float4	Position: SV_POSITION;
	float2	uv : TEXCOORD;
};

// Pass through vertex shader.
VS_OUTPUT PassThrough( float4 position: POSITIONT , float2 texcoord : TEXCOORD )
{
	VS_OUTPUT Out;
	Out.Position = position;
	Out.uv = texcoord;
	return Out;
}

// In this pass we directly draw frame to screen.
Texture2D FrameTexture;
SamplerState DirectSampler
{
    Filter = MIN_MAG_MIP_POINT;
    AddressU = Wrap;
    AddressV = Wrap;
};

float4 FrameDirectThrought( VS_OUTPUT In ) : SV_Target
{
	return FrameTexture.Sample( DirectSampler , In.uv );
}

technique10 RenderFrame {
	pass p0 {
		// states
		SetBlendState( RegularBlending , float4(1,1,1,1) , 0xffffffff );
		// shader
		SetVertexShader( CompileShader( vs_4_0 , PassThrough() ) );
		SetGeometryShader( NULL );
		SetPixelShader( CompileShader( ps_4_0 , FrameDirectThrought() ) );
	}
}

#else

// DirectX 9 version.

// In this pass we directly draw frame to screen.
texture FrameTexture;
sampler FrameSampler = sampler_state
{
    Texture = <FrameTexture>;
    MinFilter = POINT;
    MagFilter = POINT;
	AddressU = WRAP;
	AddressV = WRAP;
};

float4 FrameDirectThrought( float2 t : TEXCOORD ) : COLOR
{
	return tex2D( FrameSampler , t );
}

technique RenderFrame {
	pass p0 {
		// alpha states
		AlphaBlendEnable = True;
		SeparateAlphaBlendEnable = True;
		SrcBlend = SRCALPHA;
		DestBlend = INVSRCALPHA;
		BlendOp = ADD;
		SrcBlendAlpha = ONE;
		DestBlendAlpha = INVSRCALPHA;
		BlendOpAlpha = ADD;
		// shader
		VertexShader = NULL;
		PixelShader = compile ps_2_0 FrameDirectThrought();
	}
}

#endif
